﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.Common;
using XQ.Framework.model;

namespace lib
{
    /// <summary>
    /// 数据库连接类-接口
    /// </summary>
    public interface IDataBase
    {
        //
        int ConnectCount { get; set; }
        int QueryCount { get; set; }
        event Action OnCreateNewConnectionHandler;
        event Action OnConnectionClosed;
        //
        void SetDataBaseModel(DataBaseModelBase model);
        void SetConnectionString(string constring);
        //
        IDbCommand InitCommand();
        IDbCommand InitCommand(CommandType cmdtype);
        IDbCommand InitCommand(CommandType cmdtype, int timeOut);
        //
        int ExecuteNonQuery(string sql);
        int ExecuteNonQuery(string sql, Dictionary<string, object> sqlParams);
        int ExecuteNonQuery(string sql, IDataParameter[] sqlParams, int timeOut);
        //
        bool ExecuteAsTransaction(params Func<IDbCommand, bool>[] handlers);
        bool ExecuteAsTransaction(Dictionary<string, Dictionary<string, object>> sqlAndData);
        //
        IDataReader ExecuteReader(string sql);
        IDataReader ExecuteReader(string sql, Dictionary<string, object> sqlParams);
        IDataReader ExecuteReaderWithParams(string sql, params DbParameter[] param);
        //
        object ExecuteScalar(string sql);
        object ExecuteScalar(string sql, Dictionary<string, object> sqlParams);
        //
        DataSet ExecuteDataset(string sql);
        DataSet ExecuteDataset(string sql, Dictionary<string, object> sqlParams);
        //
        DataTable ExecuteDataTable(string sql);
        DataTable ExecuteDataTable(string sql, Dictionary<string, object> sqlParams);
        //
        T RunProcedure<T>(string storedProcName, IDataParameter[] param, out int rowsAffected);
        //
        int ExecuteFileToDb(string sql, Dictionary<string, byte[]> param);
        byte[] ReadFileFromDb(string sql, Dictionary<string, object> param);
        T FillEntity<T>(DataRow row) where T : class,new();
        void Release();

    }
}
